***********************************************************************************
* Analysis 2: What are the destinations of movers?
* Run discrete choice models for movers
* last modified 7/22/2025
*
***********************************************************************************

* ssc install lnmor /*install Karlson and Jann package on marginal odds ratios*/
clear
capture log close 
set more off

***************
* Directories *
***************

cd "/Users/"

global dofile			=	"./Code/NEW-OEWS"
global matrix_data		=   "./Data/National Employment Matrix"
global oews_data		= 	"./Data/OEWS/all_excel"
global onet_data		= 	"./OccLink/ONET/ONET data/merged"
global cps_data			= 	"./Data/CPS/IPUMS/00015"
global xwalk 			=	"./Data/Crosswalk"
global results 			=	"./Results"
global temp				= 	"./Temp"
global logfile          =   "./Results"



log using "${logfile}/TableE4.log", replace
 
****************************************
* Table 3 Discrete Choice Models       *
****************************************

use "${temp}/cps_2000-2020_choice_set_movers.dta", replace

* Generate choice variable

gen dest = (choice_occ == occ_t1)

* Generate size constraint variable

gen logemp_choice = log(empsize_choice)

* rescale growth variables in terms of 10 percent change

gen emp_pc_growth10_choice = emp_pc_growth_choice/10
gen proj_pc_growth10_choice = proj_pc_growth_choice/10


drop if emp_pc_growth_choice > 400 /* drop outliers*/

* Mark the analytical sample

mark good if emp_chng_rate_choice !=. & proj_pc_growth_choice !=. & outlook_gr_choice != . & outlook_gr_t0 != .



* m1: individual variables + 2-year employment change

gen lograte_choice = log(1+emp_chng_rate_choice)
gen lograte_t0 = log(1+emp_chng_rate_t0)

clogit dest emp_pc_growth10_choice                                   /*
*/	i.male##c.emp_pc_growth10_choice                                 /*
*/	ib2.age_gr##c.emp_pc_growth10_choice                             /*
*/	ib1.race##c.emp_pc_growth10_choice                               /*
*/	i.hispanic##c.emp_pc_growth10_choice                             /*
*/	ib1.edu_gr##c.emp_pc_growth10_choice                             /*
*/  ib1.year##c.emp_pc_growth10_choice                               /*
*/  if good == 1, group(personid) offset(logemp_choice) 


* m2: individual variables + 10-year projected growth

gen logprojrate_choice = log(1+proj_pc_growth_choice/100)
gen logprojrate_t0 = log(1+proj_pc_growth_t0/100)

clogit dest proj_pc_growth10_choice                               /*
*/	i.male##c.proj_pc_growth10_choice                             /*
*/	ib2.age_gr##c.proj_pc_growth10_choice                         /*
*/	ib1.race##c.proj_pc_growth10_choice                           /*
*/	i.hispanic##c.proj_pc_growth10_choice                         /*
*/	ib1.edu_gr##c.proj_pc_growth10_choice                         /*
*/  ib1.year##c.proj_pc_growth10_choice                           /*
*/  if good == 1, group(personid) offset(logemp_choice) 


* m3: individual variables + projected OOH outlook categories

* Generate destination outlook dummy variable
generate out1 = (outlook_gr_choice==1)
generate out3 = (outlook_gr_choice==3)

*Generate origin and destination outlook interaction dummy variable
generate origin1_1 = (outlook_gr_t0 == 1) * out1
generate origin1_3 = (outlook_gr_t0 == 1) * out3
generate origin3_1 = (outlook_gr_t0 == 3) * out1
generate origin3_3 = (outlook_gr_t0 == 3) * out3


clogit dest ib2.outlook_gr_choice                                 /*
*/	i.male##ib2.outlook_gr_choice                                 /*
*/	ib2.age_gr##ib2.outlook_gr_choice                             /*
*/	ib1.race##ib2.outlook_gr_choice                               /*
*/	i.hispanic##ib2.outlook_gr_choice                             /*
*/	ib1.edu_gr##ib2.outlook_gr_choice                             /*
*/  ib1.year##ib2.outlook_gr_choice                               /*
*/  if good == 1, group(personid) offset(logemp_choice) 


* m4:interactions between origin and destination outlook
clogit dest ib2.outlook_gr_choice                                 /*
*/  ib2.outlook_gr_t0##ib2.outlook_gr_choice                      /*
*/	i.male##ib2.outlook_gr_choice                                 /*
*/	ib2.age_gr##ib2.outlook_gr_choice                             /*
*/	ib1.race##ib2.outlook_gr_choice                               /*
*/	i.hispanic##ib2.outlook_gr_choice                             /*
*/	ib1.edu_gr##ib2.outlook_gr_choice                             /*
*/  ib1.year##ib2.outlook_gr_choice                               /*
*/  if good == 1, group(personid) offset(logemp_choice) 

lnmor ib2.outlook_gr_choice, or
lnmor outlook_gr_t0##ib2.outlook_gr_choice, or
lnmor ib2.outlook_gr_t0##ib2.outlook_gr_choice, or


/* test results without controls */

clogit dest ib2.outlook_gr_choice                                 /*
*/  if good == 1, group(personid) offset(logemp_choice) 

clogit dest ib2.outlook_gr_choice                                 /*
*/  if good == 1, group(personid) 

log close
